<!--#
layout("/layouts/platform.html"){
#-->
<style>
    .el-upload input[type=file] {
        display: none;
    }

    .el-upload__text {
        color: #606266;
        font-size: 14px;
        text-align: center;
    }
</style>
<div id="app"  v-cloak>
    <!--<div class="head"><div class="headone"><i class="el-icon-menu"></i><span >厂家信息</span></div></div>-->
    <el-row class="header navbar bg-white">
        <div class="btn-group tool-button" style="line-height: 50px;">
            <el-input placeholder="设备编号" v-trim v-model="pageForm.code" size="mini" style="width:180px;" clearable></el-input>
            <el-input placeholder="设备名称" v-trim v-model="pageForm.name" size="mini" style="width:180px;" clearable></el-input>
            <el-cascader placeholder="申请状态" v-if="pageForm.processName == 'ask'" v-trim v-model="pageForm.lczt" size="mini" :options="allMap.processOptions" clearable style="width:180px;"></el-cascader>
            <el-button slot="append" icon="el-icon-search" size="mini" @click="doSearch" circle></el-button>
        </div>
        <div v-if="pageForm.processName == 'ask'" class="pull-right offscreen-right" style="margin-right: 20px;line-height: 50px;">
             <el-tooltip class="item" effect="dark" content="新增">
                    <el-button type="primary" icon="el-icon-plus"  size="mini" @click="openAddDialog" circle></el-button>
             </el-tooltip>
        </div>
    </el-row>

    <el-row class="el-table-container">
        <el-table :data="tableData" @sort-change='pageOrder' height="520"  border size="small" header-align="center"  style="width: 100%" >
            <el-table-column
                    fixed="left"
                    prop="note"
                    label="操作"
                    width="120" header-align="center" align="center" >
                <template slot-scope="scope">
                    <el-dropdown @command="dropdownCommand" >
                        <el-button size="mini">
                            <i class="ti-settings"></i>
                            <span class="ti-angle-down"></span>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item v-if="scope.row.lczt == 0 && scope.row.opby == '${userId}'" divided :command="{type:'sub',row:scope.row}">
                                提交
                            </el-dropdown-item>
                            <el-dropdown-item v-if="(scope.row.lczt == 0 || scope.row.lczt == 3) && scope.row.opby == '${userId}'" divided :command="{type:'edit',row:scope.row}">
                                修改
                            </el-dropdown-item>
                            <el-dropdown-item v-if="(scope.row.lczt == 0 || scope.row.lczt == 3) && scope.row.opby == '${userId}'" divided :command="{type:'delete',row:scope.row}">
                                删除
                            </el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.lczt != 0 && pageForm.processName=='audit'" divided :command="{type:'process',row:scope.row}">
                                审核
                            </el-dropdown-item>
                            <el-dropdown-item divided :command="{type:'detail',row:scope.row}">
                                详情
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
            <el-table-column fixed="left" sortable="custom" prop="code" label="设备编号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="lczt" label="申请状态" width="140px;" header-align="center"  align="center" show-overflow-tooltip>
                <template slot-scope="scope" ><span :class="'sbstatusCss-'+scope.row.lczt"><i :class="'sbel-icon-'+scope.row.lczt"/>{{getDict(scope.row.lczt,allMap.processMap)}}</span></template>
            </el-table-column>
            <el-table-column v-if="pageForm.processName=='ask'"  prop="nextspr" label="下一步审核人" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="name" label="设备名称" width="200px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="model" label="规格型号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="company" label="制造厂商" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="purchasedate" label="购置日期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="purchaseprice" label="购置价格" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >
                    {{scope.row.purchaseprice}} 元
                </template>
            </el-table-column>
            <el-table-column  prop="residualvalue" label="估计残值" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >
                    {{scope.row.residualvalue}} 元
                </template>
            </el-table-column>
            <el-table-column  prop="purpose" label="用途" min-width="320px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="scraotype" label="报废类别" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >
                    <span v-if="scope.row.scraotype=='1'">设备</span>
                    <span v-else>器具</span>
                </template>
            </el-table-column>
            <el-table-column  prop="explains" label="报废原因" min-width="320px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="appraisalopinion" label="鉴定及处理意见" min-width="320px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>

        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination @size-change="pageSizeChange" @current-change="pageNumberChange" :current-page="pageForm.pageNumber" :page-sizes="[10, 20, 30, 50]"
                       :page-size="pageForm.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageForm.totalCount">
        </el-pagination>
    </el-row>

    <el-dialog :close-on-click-modal="false" append-to-body   title="设备报废申请"  :visible.sync="addDialogVisible" width="1200px">
        <el-form id="addForm"  :rules="formRules" :model="formData" ref="addForm"  size="small" label-width="120px" >
            <el-row :gutter="20" border>
                <el-col :span="8">
                    <el-form-item prop="code" label="设备编号" >
                        <el-input readonly maxlength="16"v-trim v-model="formData.code" type="text" style="width: 150px;"></el-input>
                        <el-button type="primary" size="mini" @click="openEquipment" plain>选择设备</el-button>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="name" label="设备名称" >
                        <el-input readonly maxlength="16"v-trim v-model="formData.name" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="model" label="规格型号">
                        <el-input readonly maxlength="32"v-trim v-model="formData.model" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="company" label="制造厂商" >
                        <el-input readonly maxlength="32"v-trim v-model="formData.company" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="purchaseDate" label="购置日期" >
                        <el-input readonly maxlength="32"v-trim v-model="formData.purchaseDate" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="purchasePrice" label="购置价格" >
                        <el-input readonly maxlength="32"v-trim v-model="formData.purchasePrice" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="residualValue" label="估计残值" >
                        <el-input-number  v-trim v-model="formData.residualValue" type="text"></el-input-number> 元
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="scraoType" label="报废类别" >
                        <el-radio-group v-model="formData.scraoType">
                            <el-radio label="1">设备</el-radio>
                            <el-radio label="2">器具</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="purpose" label="用途" >
                        <el-input maxlength="125" v-trim v-model="formData.purpose" type="textarea"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="explains" label="报废原因" >
                        <el-input maxlength="125" v-trim v-model="formData.explains" type="textarea"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="appraisalOpinion" label="鉴定及处理意见" >
                        <el-input maxlength="125" v-trim v-model="formData.appraisalOpinion" type="textarea"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="相关附件">
                        <el-upload
                                class="upload-demo"
                                name="Filedata"
                                action="${base}/open/file/upload/file1"
                                :on-remove="handleRemove"
                                :before-remove="beforeRemove"
                                :on-success="handleSuccess"
                                multiple
                                :limit="3"
                                :on-exceed="handleExceed"
                                :file-list="fileList">
                            <el-button size="small" type="primary">点击上传</el-button>
                        </el-upload>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="nextsprIds" label="选择审核人" >
                        <el-cascader v-model="formData.nextsprIds" size="mini" :options="userOptions"  ref="shrCascader" placeholder="搜索"  style="width:180px;" filterable></el-cascader>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="addDialogVisible = false;fileList=[]">取 消</el-button>
            <el-button type="success" @click="doAdd">保 存</el-button>
            <el-button type="primary" @click="doSub">提 交</el-button>
        </span>
    </el-dialog>

    <el-dialog title="选择设备" :visible.sync="visibleEquipment" width="80%"  append-to-body>
        <el-row class="bg-white">
            <div class="btn-group tool-button" style="line-height: 50px;">
                <el-input placeholder="设备编号" v-trim v-model="pageFormEquipment.code" size="mini" style="width:180px;" clearable></el-input>
                <el-input placeholder="设备名称" v-trim v-model="pageFormEquipment.name" size="mini" style="width:180px;" clearable></el-input>
                <el-button slot="append" icon="el-icon-search" size="mini" @click="doSearchEquipment" circle></el-button>
            </div>
        </el-row>
        <el-row>
            <el-table :data="tableDataEquipment" @sort-change='pageOrderEquipment' height="400"  border
                      ref="multipleTableEquipment" @select-all="selectAll"
                      size="small" header-align="center"  style="width: 100%" @selection-change="handleSelectionChange">
                <el-table-column type="selection" label="选择" width="55px;" header-align="center" align="center"></el-table-column>

                <el-table-column fixed="left" sortable="custom" prop="code" label="设备编号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column fixed="left" sortable="custom" prop="name" label="设备名称" width="200px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="model" label="规格型号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="detectionrange" label="检测范围" width="220px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="accuracy" label="精度要求" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="factorycode" label="出厂编号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="number" label="数量（台/套）" min-width="130px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="company" label="制造厂商" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="purchaseprice" label="购置价格（元）" min-width="130px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="purchasedate" label="购置日期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="calculate" label="溯源方式" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                    <template slot-scope="scope" >{{getDict(scope.row.calculate,allMap.calculateMap)}}</template>
                </el-table-column>
                <el-table-column  prop="calculateunit" label="溯源单位" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="calculatecycle" label="溯源周期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                    <template slot-scope="scope" >{{scope.row.calculatecycle}}{{getDict(scope.row.calculatecycletype,allMap.calculateCycleTypeMap)}}</template>
                </el-table-column>
                <el-table-column sortable="custom" prop="calculatedate" label="下次溯源日期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="depositadress" label="存放地点" min-width="220px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="managername" label="设备责任人" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="applyname" label="使用部门" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="classification" label="分类情况" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="importedflag" label="是否进口设备" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="assetcode" label="资产编号" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="supplyphone" label="供货商联系电话" min-width="150px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="remark" label="备注" min-width="320px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>

            </el-table>
        </el-row>
        <el-row class="el-pagination-container">
            <el-pagination @size-change="pageSizeChangeEquipment" @current-change="pageNumberChangeEquipment" :current-page="pageFormEquipment.pageNumber" :page-sizes="[10, 20, 30, 50]"
                           :page-size="pageFormEquipment.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageFormEquipment.totalCount">
            </el-pagination>
        </el-row>

        <span slot="footer" class="dialog-footer">
            <el-button @click="visibleEquipment = false">取 消</el-button>
            <el-button type="primary" @click="setEquipment">确 定</el-button>
        </span>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" title="设备报废审核" :visible.sync="processDialogVisible" width="800px">
        <el-form :model="processFormData" ref="processForm" :rules="processRules"  size="mini" label-width="120px" >

            <el-row :gutter="20" border>
                <el-col :span="24">
                    <el-form-item prop="name" label="设备名称">
                        {{processFormData.name}}&nbsp;&nbsp;（编号：{{processFormData.code}}）&nbsp;&nbsp;
                        <el-link type="primary" size="mini" @click="dropdownCommand({type:'detail',row:processFormData})">详情查看</el-link>&nbsp;&nbsp;&nbsp;&nbsp;
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20" border >
                <el-col :span="12">
                    <el-form-item prop="status" label="审核状态" >
                        <el-radio-group v-model="processFormData.status" size="mini"  @change="setFlag">
                            <el-radio label="0" border>审核通过</el-radio>
                            <el-radio label="1" border>审核不通过</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="auditFlag" label="是否办结" >
                        <el-radio-group v-model="processFormData.auditFlag" size="mini">
                            <el-radio label="0" border v-if=" processFormData.status == '0'">否</el-radio>
                            <el-radio label="1" border>是</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12" v-if="processFormData.auditFlag == '0' && processFormData.status == '0'">
                    <el-form-item prop="nextsprIds" label="下一步审核人" >
                        <el-cascader v-model="processFormData.nextsprIds" size="mini" :options="userOptions"  ref="auditCascader" placeholder="搜索"  style="width:180px;" filterable></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="opinion" label="意见">
                        <el-autocomplete
                                v-trim v-model="processFormData.opinion"
                                :fetch-suggestions="termSearch"
                                value-key="content"
                                clearable
                                placeholder="请输入审核意见"
                                type="textarea"
                                style="width:100%;"
                                rows="3"
                                maxlength="255"
                        />
                    </el-form-item>

                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="processDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="processDo">提 交</el-button>
        </span>
    </el-dialog>
    <el-drawer :wrapperClosable="false" title="详情" :visible.sync="drawer" direction="rtl" size="80%"  destroy-on-close>
        <el-form :model="detailFormData" size="small" label-width="120px" class="overflowAuto">
            <el-collapse v-model="activeNames" >
                <el-collapse-item title="申请信息" name="1">
                    <el-row :gutter="20" border>
                        <el-col :span="8">
                            <el-form-item label="设备编号" >
                                {{detailFormData.code}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="设备名称" >
                                {{detailFormData.name}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="规格型号">
                                {{detailFormData.model}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="制造厂商" >
                                {{detailFormData.company}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="购置日期" >
                                {{detailFormData.purchaseDate}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="购置价格" >
                                {{detailFormData.purchasePrice}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="估计残值" >
                                {{detailFormData.scrap.residualValue}}元
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="报废类别" >
                                <span v-if="detailFormData.scrap.scraoType == '1'">设备</span>
                                <span v-else>器具</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="用途" >
                                {{detailFormData.scrap.purpose}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="报废原因" >
                                {{detailFormData.scrap.explains}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="鉴定及处理意见" >
                                {{detailFormData.scrap.appraisalOpinion}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="相关附件" >
                                <template v-for="item in fileList">
                                    <el-link :href="AppFile+item.response.data.filePath" target="_blank">{{item.name}}</el-link><br>
                                </template>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>
                <el-collapse-item title="申请过程" name="2">
                    <el-row :gutter="20">
                        <el-table :data="detailFormData.listProcess" border size="small" header-align="center"  style="width: 100%">
                            <el-table-column prop="opname" label="操作人" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                            <el-table-column prop="optime" label="操作时间" width="140px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                            <el-table-column prop="lczt" label="申请状态" width="140px;" header-align="center" align="center" show-overflow-tooltip>
                                <template slot-scope="scope" ><span :class="'sbstatusCss-'+scope.row.lczt"><i :class="'sbel-icon-'+scope.row.lczt"/>{{getDict(scope.row.lczt,allMap.processMap)}}</span></template>
                            </el-table-column>
                            <el-table-column prop="nextspr" label="下一步审核人" width="140px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                            <el-table-column prop="opinion" label="审核意见"  header-align="center" align="center" show-overflow-tooltip></el-table-column>
                        </el-table>
                    </el-row>
                </el-collapse-item>
            </el-collapse>
        </el-form>
    </el-drawer>
</div>
<style scoped>
    .el-table--border th.gutter:last-of-type {
        display: block !important;
        width: 17px !important;
    }

</style>
<script>
    var allMap = {processMap:${processMap},processOptions:${processOptions},calculateMap:${calculateMap},calculateCycleTypeMap:${calculateCycleTypeMap}}
    new Vue({
        el: "#app",
        data: function () {
            return {
                allMap:allMap,
                userOptions:[],
                tableData: [],
                addDialogVisible:false,
                pageForm: {processName:"${processName}"},
                formData: {},
                formRules: {
                    code: [{required: true, message: '设备编号', trigger: ['blur', 'change']}],
                    name: [{required: true, message: '设备名称', trigger: ['blur', 'change']}],
                    residualValue:[{required: true, message: '估计残值', trigger: ['blur', 'change']}],
                    scraoType:[{required: true, message: '报废类别', trigger: ['blur', 'change']}],
                    purpose:[{required: true, message: '用途', trigger: ['blur', 'change']}],
                    explains:[{required: true, message: '原因说明', trigger: ['blur', 'change']}],
                    appraisalOpinion:[{required: true, message: '鉴定及处理意见', trigger: ['blur', 'change']}],
                    nextsprIds:[{required: true, message: '审核人不能为空！', trigger: ['blur', 'change']}],
                },
                tableDataEquipment: [],
                pageFormEquipment: {status:1},
                visibleEquipment:false,
                multipleSelectionEquipment:[],
                processDialogVisible:false,
                processFormData:{},
                processRules:{
                    status: [{required: true, message: '审核状态', trigger: ['blur', 'change']}],
                    opinion: [{required: true, message: '审核意见', trigger: ['blur', 'change']}],
                    nextsprIds:[{required: true, message: '审核人不能为空！', trigger: ['blur', 'change']}],
                    auditFlag:[{required: true, message: '办结状态不能为空！', trigger: ['blur', 'change']}],
                },
                drawer: false,
                detailFormData:{scrap:{},listProcess:[]},
                activeNames: ['1','2'],
                AppFile:"${AppFileDomain}${AppUploadBase}",
                fileList: []
            }
        },
        methods: {
            openEquipment:function(){
                this.visibleEquipment = true;
                this.doSearchEquipment();
            },
            openAddDialog:function(){
                this.addDialogVisible=true;
                this.formData ={scraoType:"1",residualValue:0}//打开新增窗口,表单先清空
                if (this.$refs["addForm"])
                    this.$refs["addForm"].resetFields();
                this.getUserSAudit("")
                this.fileList=[]
                this.formData=JSON.parse(JSON.stringify(this.formData));
            },
            doSub:function(){
                var self = this;
                self.$confirm('确定提交吗？提交后将无法修改', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    callback: function (a, b) {
                        if ("confirm" == a) {//确认后再执行
                            self.formData.lczt = "1";
                            self.save();
                        }
                    }
                });
            },
            doAdd: function () {
                this.formData.lczt="0";
                this.save();
            },
            save:function(){
                var self = this;
                self.$refs["addForm"].validate(function (valid) {
                    if (valid) {
                        var url = "/platform/bus/equipment/scrap/addDo";
                        if(nONull(self.formData.id)){
                            url = "/platform/bus/equipment/scrap/editDo";
                        }
                        if(nONull(self.formData.nextsprIds)){
                            self.formData.nextsprIds = self.formData.nextsprIds.join(",");
                            self.formData.nextspr = self.$refs['shrCascader'].getCheckedNodes()[0].label;
                        }
                        $.post(base + url, self.formData, function (data) {
                            if (data.code == 0) {
                                self.$message({message: data.msg,type: 'success'});
                                self.addDialogVisible = false;
                                self.fileList=[];
                                self.pageData();//添加失败也可以入库,所以加载一下看看
                            } else {
                                if(nONull(self.formData.nextsprIds)){self.formData.nextsprIds=self.formData.nextsprIds.split(",");}
                                self.$message({
                                    message: data.msg,
                                    type: 'error'
                                });
                            }
                        }, "json");
                    }
                });
            },
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                if(nONull(self.pageForm.lczt)){self.pageForm.lczt = self.pageForm.lczt.join(",");}
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/bus/equipment/scrap/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                    if(nONull(self.pageForm.lczt)){self.pageForm.lczt = self.pageForm.lczt.split(",");}
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },

            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                if ("delete" == command.type) {
                    self.$confirm('此操作将删除 ' + command.row.name, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/bus/equipment/scrap/delete/" + command.row.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
                if("edit" == command.type){//修改
                    //根据id获取数据
                    $.post(base + "/platform/bus/equipment/scrap/detail/" + command.row.id, {}, function (data) {
                        if (data.code == 0) {
                            self.formData =  data.data.scrap;
                            self.formData.code=command.row.code;
                            self.formData.name=command.row.name;
                            self.formData.model=command.row.model;
                            self.formData.company=command.row.company;
                            self.formData.purchaseDate=command.row.purchasedate;
                            self.formData.purchasePrice=command.row.purchaseprice;
                            self.setFile(self.formData.fileId);
                            if(nONull(self.formData.nextsprIds)){self.formData.nextsprIds=self.formData.nextsprIds.split(",");}
                            self.formData = JSON.parse(JSON.stringify(self.formData))
                            self.getUserSAudit(self.formData.opBy);
                        } else {
                            self.$message({message: data.msg,type: 'error'});
                        }
                    }, "json");
                    //打开窗口
                    this.addDialogVisible=true;
                }
                if("sub" == command.type){//提交
                    //根据id获取数据
                    $.post(base + "/platform/bus/equipment/scrap/subDo/" + command.row.id, {}, function (data) {
                        if (data.code == 0) {
                            self.pageData();//添加失败也可以入库,所以加载一下看看
                            self.$message({message: data.msg,type: 'success' });
                        } else {
                            self.$message({message: data.msg,type: 'error'});
                        }
                    }, "json");
                }
                if("process" == command.type){//审核
                    //根据id获取数据
                    $.post(base + "/platform/bus/equipment/scrap/detail/" + command.row.id, {}, function (data) {
                        if (data.code == 0) {
                            self.processFormData =  data.data.scrap;
                            self.processFormData.code=command.row.code;
                            self.processFormData.name=command.row.name;
                            self.processFormData.model=command.row.model;
                            self.processFormData.company=command.row.company;
                            self.processFormData.purchaseDate=command.row.purchasedate;
                            self.processFormData.purchasePrice=command.row.purchaseprice;
                            self.processFormData.purchasedate=command.row.purchasedate;
                            self.processFormData.purchaseprice=command.row.purchaseprice;
                            self.processFormData.nextsprIds=[];
                            self.processFormData.nextspr="";
                            self.processFormData.status="0";
                            self.processFormData.auditFlag="1";
                            self.processFormData = JSON.parse(JSON.stringify(self.processFormData))
                            self.getUserSAudit(self.processFormData.opBy);
                        } else {
                            self.$message({message: data.msg,type: 'error'});
                        }
                    }, "json");
                    //打开窗口
                    self.processDialogVisible=true;
                }
                if("detail" == command.type){//详情
                    //根据id获取数据
                    $.post(base + "/platform/bus/equipment/scrap/detail/" + command.row.id, {}, function (data) {
                        if (data.code == 0) {
                            self.detailFormData =  data.data;
                            self.detailFormData.code=command.row.code;
                            self.detailFormData.name=command.row.name;
                            self.detailFormData.model=command.row.model;
                            self.detailFormData.company=command.row.company;
                            self.detailFormData.purchaseDate=command.row.purchasedate;
                            self.detailFormData.purchasePrice=command.row.purchaseprice;
                            self.setFile(self.detailFormData.scrap.fileId);
                        } else {
                            self.$message({message: data.msg,type: 'error'});
                        }
                    }, "json");
                    //打开窗口
                    this.drawer=true;
                }
            },
            processDo: function(){
                var self = this;
                self.$refs["processForm"].validate(function (valid) {
                    if (valid) {
                        var url = "/platform/bus/equipment/scrap/processDo";
                        if(nONull(self.processFormData.nextsprIds)&&self.processFormData.auditFlag=="0"){
                            self.processFormData.nextsprIds=self.processFormData.nextsprIds.join(",");
                            self.processFormData.nextspr = self.$refs['auditCascader'].getCheckedNodes()[0].label;
                        }else{
                            self.processFormData.nextsprIds=[];
                        }
                        $.post(base + url, self.processFormData, function (data) {
                            if (data.code == 0) {
                                self.$message({message: data.msg,type: 'success'});
                                self.processDialogVisible = false;
                                self.pageData();//添加失败也可以入库,所以加载一下看看
                            } else {
                                if(nONull(self.processFormData.nextsprIds)&&self.processFormData.auditFlag=="0"){self.processFormData.nextsprIds=self.processFormData.nextsprIds.split(",");}
                                self.$message({
                                    message: data.msg,
                                    type: 'error'
                                });
                            }
                        }, "json");
                    }
                });
            },
            getUserSAudit: function(userId){
                var self = this;
                $.post(base + "/platform/sys/user/getUserSAudit", {userId:userId}, function (data) {
                    if (data.code == 0) {
                        self.userOptions = data.data;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            getDict: function (val,map) {
                if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined" && map!=null && map !=undefined){
                    var str = val.split(",");
                    var strname="";
                    for (var a=0;a<str.length;a++){
                        strname+=map[str[a]];
                        if(strname == null){
                            alert(1)
                        }
                        if(a<(str.length-1)){
                            strname+="/";
                        }
                    }
                    return strname;
                }
                return "";
            },
            selectAll(){
                this.$nextTick(() => {
                    this.$refs.multipleTableEquipment.clearSelection();
                });
            },
            handleSelectionChange: function (val) {
                //this.$refs.multipleTableEquipment.toggleRowSelection(val);
                val.forEach((item,index)=>{
                    //console.log(val.length,index,item.name)
                    if(index<val.length-1){
                        val.splice(index,1)
                        this.$refs.multipleTableEquipment.toggleRowSelection(item,false);
                    }
                })
                //console.log(val,"--------------")
                this.multipleSelectionEquipment=val;
                //this.visibleEquipment = false;
            },
            setEquipment:function(){
                var self = this;
                if(self.multipleSelectionEquipment.length==0){
                    self.$message({message: "请选择设备！",type: 'error'});
                    return;
                }
                var equipment = self.multipleSelectionEquipment[0];
                self.formData.equipmentId=equipment.id;
                self.formData.code=equipment.code;
                self.formData.name=equipment.name;
                self.formData.model=equipment.model;
                self.formData.company=equipment.company;
                self.formData.purchaseDate=equipment.purchasedate;
                self.formData.purchasePrice=equipment.purchaseprice;
                self.formData = JSON.parse(JSON.stringify(self.formData))
                self.visibleEquipment = false;
            },
            pageOrderEquipment: function (column) {//按字段排序
                this.pageFormEquipment.pageOrderName = column.prop;
                this.pageFormEquipment.pageOrderBy = column.order;
                this.pageDataEquipment();
            },
            pageNumberChangeEquipment: function (val) {//页码更新操作
                this.pageFormEquipment.pageNumber = val;
                this.pageDataEquipment();
            },
            pageSizeChangeEquipment: function (val) {//分页大小更新操作
                this.pageFormEquipment.pageSize = val;
                this.pageDataEquipment();
            },
            pageDataEquipment: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/bus/equipment/data", self.pageFormEquipment, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableDataEquipment = data.data.list;
                        self.pageFormEquipment.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearchEquipment: function () {
                this.pageFormEquipment.pageNumber = 1;
                this.pageDataEquipment();
            },
            termSearch(val, cb){
                var company = [];
                var searchForm ={
                    name:val
                }
                $.post(base + "/platform/bus/term/list", searchForm, function (data) {
                    if (data.code == 0) {
                        company= data.data;
                        //return company;
                        cb(company)
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            handleRemove: function (file, fileList) {
                var self = this;
                var thisData = file.response.data;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/open/file/upload/delFile/"+thisData.id, {}, function (data) {
                    if (data.code == 0) {
                        sublime.closeLoadingbar();//关闭loading
                        self.$message({message: data.msg,type: 'success'});
                        if(self.formData.fileId && self.formData.fileId!=""){
                            if(self.formData.fileId.split(",").length>1){
                                self.formData.fileId = self.formData.fileId.replace(","+thisData.id,"");
                            }else{
                                self.formData.fileId = "";
                            }
                        }
                    } else {
                        self.$message({message: data.msg,type: 'error'});
                    }
                }, "json");
            },
            handleExceed: function (files, fileList) {
                this.$message.warning(`当前限制选择 3 个文件，本次选择了 `+files.length+` 个文件，共选择了 `+(files.length + fileList.length)+` 个文件`);
            },
            beforeRemove: function (file) {
                return this.$confirm(`确定移除 `+file.name+`？`);
            },
            handleSuccess:function(file){
                if(this.formData.fileId && this.formData.fileId!=""){
                    this.formData.fileId += ","+file.data.id;
                }else{
                    this.formData.fileId = file.data.id;
                }
            },
            setFile: function (fileId) {
                var self = this;
                self.fileList=[];
                if(fileId && fileId!=""){
                    var fileIds = fileId.split(",")
                    for(var i=0;i<fileIds.length;i++){
                        $.post(base + "/open/file/upload/getFile/"+fileIds[i], {}, function (data) {
                            if (data.code == 0) {
                                var file = {
                                    name:data.data.fileBeforeName,
                                    response:{
                                        data:data.data
                                    }
                                }
                                self.fileList.push(file);
                            } else {
                                self.$message({message: data.msg,type: 'error'});
                            }
                        }, "json");
                    }

                }
            },
            setFlag(){
                if(this.processFormData.status=='1'){
                    this.processFormData.auditFlag='1';
                    this.processFormData.nextsprIds=undefined;
                }
            }
        },
        created: function () {
            this.doSearch();
        }
    });

    function nONull(val){
        if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined" ){
            return true;
        }else{
            return false;
        }
    }
</script>

<style>
    .el-autocomplete-suggestion{
        transform-origin: center top;
        z-index: 2015;
        position: fixed;
    }
    /*.el-autocomplete-suggestion li{
        white-space:normal;
        line-height:15px;
        font-size:11px;
    }*/

    .overflowAuto {
        padding-left: 20px;
        overflow-y: auto;
        position: absolute;
        width: 100%;
        height: 100%;
    }
    .overflowAuto::-webkit-scrollbar {
        height: 6px;
        width: 6px;
    }
    .overflowAuto::-webkit-scrollbar-thumb {
        background: rgb(224, 214, 235);
    }

</style>
<!--#
}
#-->
